package com.yangc.thread.virtual;

import java.io.IOException;
import java.util.concurrent.ThreadFactory;

public class VirtualThreadDemo {
    public static void main(String[] args) throws IOException {
        // 启动一个虚拟线程执行任务
        Thread.startVirtualThread(() -> {
            System.out.println("这是一个虚拟线程：" + Thread.currentThread().threadId());
        });

        // 使用线程工厂批量创建虚拟线程
        ThreadFactory factory = Thread.ofVirtual().factory();
        Runnable task = () -> System.out.println("任务执行：" + Thread.currentThread().threadId());
        factory.newThread(task).start();

        System.in.read();
    }
}
